<?php
namespace app\api\controller;

use app\BaseController;
use app\common\model\mysql\YwCustomer as models;

class User extends BaseController
{

    public function initialize()
    {
    }

    /*
     * 绑定银行卡
     */
    public function submitBank(){
        $fildes = 'token,bank_name,id_number,bank_number,bank_account,bank_mobile,remark';
        $receiveData = getData($this->request->post(),$fildes);
        if(empty($receiveData['bank_name'])){
            jsonFail('请输入开户人姓名');
        }
        if(empty($receiveData['bank_number'])){
            jsonFail('请输入银行卡号');
        }
        if(empty($receiveData['bank_account'])){
            jsonFail('请输入开户行信息');
        }
        if(empty($receiveData['id_number'])){
            jsonFail('请输入身份证号');
        }
        //校验token
        $admin = models::checkToken($receiveData['token']);
        models::where(['id'=>$admin['id']])->update([
            'bank_name' => $receiveData['bank_name'],
            'bank_number' => $receiveData['bank_number'],
            'bank_account' => $receiveData['bank_account'],
            'bank_mobile' => $receiveData['bank_mobile'],
            'id_number' => $receiveData['id_number'],
            'remark' => $receiveData['remark'],
            'is_valid' => 1
        ]);
        jsonSuccess();
    }

    /*
     * 更改头像
     */
    public function updateHeadPic(){
        $fildes = 'token,head_pic';
        $receiveData = getData($this->request->post(),$fildes);
        $customer = models::checkToken($receiveData['token']);
        models::where(['id'=>$customer['id']])->update([
            'head_pic' => $receiveData['head_pic'],
        ]);
        jsonSuccess();
    }

    /*
     * 加载登录人信息
     */
    public function load(){
        $fildes = 'token';
        $receiveData = getData($this->request->post(),$fildes);
        $customer = models::checkToken($receiveData['token']);
        $data = [
            'username' => $customer['username'],
            'mobile' => $customer['mobile'],
            'price' => $customer['price'],
            'bank_name' => $customer['bank_name'],
            'bank_number' => $customer['bank_number'],
            'bank_account' => $customer['bank_account'],
            'bank_mobile' => $customer['bank_mobile'],
            'id_number' => $customer['id_number'],
            'is_valid' => $customer['is_valid'],
            'id' => $customer['id'],
            'head_pic' => $customer['head_pic'],
            'id_number_d' => $customer['id_number'],
            'bank_number_d' => $customer['bank_number'],
        ];
        jsonSuccess($data);
    }

}
